package com.usefullc.extinguisher.service;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.usefullc.extinguisher.domain.FireDeviceAuditRecord;
import com.usefullc.extinguisher.query.FireDeviceAuditRecordQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Sampson
 * @date: 2022-10-22 17:41
 */
@Service
@Slf4j
public class ExtinguisherTestService {

    @Autowired
    private FireDeviceAuditRecordService fireDeviceAuditRecordService;

    public void test1(){
        List<FireDeviceAuditRecord> dataList = fireDeviceAuditRecordService.findAll(new FireDeviceAuditRecordQuery());
        for (FireDeviceAuditRecord fireDeviceAuditRecord : dataList) {
            int status = RandomUtils.nextInt(0, 3);
            int dayNum = RandomUtils.nextInt(0, 366);
            DateTime date = DateUtil.date();
            date.setField(DateField.HOUR_OF_DAY,RandomUtils.nextInt(0,23));
            DateTime gmtAudit = DateUtil.offsetDay(date, -dayNum);
            fireDeviceAuditRecord.setStatus(status);
            if(status != 0){
                fireDeviceAuditRecord.setGmtAudit(gmtAudit);
            }
            fireDeviceAuditRecordService.update(fireDeviceAuditRecord);
        }
    }
}
